# 1. 变量在单独上下文中定义，不能在上下文之外访问
## 上下文：不固定大小的模块
def getSum(a, b):
    SUM = a + b
    return SUM


# print(SUM)
# SUM++

# 2. 缩进的规则
## 代码和循环同级，循环后执行；代码比循环低一级，在循环中执行
for i in range(3):
    print(i)
    if i == 1:
        break  # 只能在循环里面用
print("a")
print("b")
# exit() # 全局方法：中断
print("c")

# 3. 代码嵌套
print("加法和：", getSum(10, 20))
a = 1
b = 2
c = 3
d = 4
print(getSum(getSum(getSum(a, b), c), d))
ab = getSum(a, b)
abc = getSum(ab, c)
abcd = getSum(abc, d)
print(abcd)

# 注释
## #后代码不被编译
## ctrl + /
## command + /

# list 切片
# : 左右索引的间隔
list = [1,2,3,4]
print(list[0])
print(list[-1])
# 左闭右开
print(list[0:2])
print("负索引",list[-1:0:-1]) # 负索引转换成正索引来进行步进
print("负索引",list[3:0:-1])
print(list[0:2:1]) # 步进器默认是1

# 没有指定索引 从尽头开始
print(list[:2])
print(list[2:])
print(list[:])
print(list[3:0:1])

print(list[0:3:2])  # 步进器
print(list[3:0:-1])  # 步进器为负，左大右小才有数
print(list[::-1])

# string 切片和list规则完全一致 ，但是string 返回string，list返回list
string = "i am fine"
print("Sting切换",string[0])
print(string[-1])
# 左闭右开
print(string[0:2])
print("负索引",string[-1:0:-1]) # 负索引转换成正索引来进行步进
print("负索引",string[8:0:-1])
print(string[0:2:1]) # 步进器默认是1

# 没有指定索引 从尽头开始
print(string[:2])
print(string[2:])
print(string[:])
print(string[3:0:1])

print(string[0:3:2])  # 步进器
print(string[3:0:-1])  # 步进器为负，左大右小才有数
print(string[::-1])

# 比较符
print("比较符")
print(1>2)
print(2>=2)
print(2<1)
print(2<=3)
print(1==2)
print(string == "i am fine") # 一个等号是赋值，两个等号是判断
print(1!=2)


# 控制结构
print("控制结构")
## 1. 顺序执行
## 2. 选择执行 if else elif
### 括号里面是判断条件 判断条件里面只能是布尔变量True 或 False
### 当括号里面不是布尔变量时 变量为None（空字符串，0，空列表……） == False  不为None == True
integer=-1
if (not integer):
    print("True时才会输出")
## 3. 循环结构
if (1>2):
    print("1>2")
if (2>=2):
    print("2>=2")
if (1):
    print("非None")
if (None):
    print("None")
b = 101
# and 且
# or 或
# not 非
if (b >= 60 and b <= 80):
    print("及格")
elif (b>80 and b<=100):
    print("优秀")
elif (b>50 and b<60):
    print("可以捞")
else:
    print("不及格")

## for循环
n = 5
for i in range(n):
    print(i,end=",")
print()
list = [1,2,3,4]
for i in list:
    print(i,end=",")
print()

tuple = (0,1,2)
for i in tuple:
    print(i,end=",")
print()

dict = {"1":"一","2":"二"}
for key in dict:
    print(key,end=",")
    print(dict.get(key),end=",")
    print()
string = "i am fine"
for i in string:
    print(i,end=",")
print()

# count = 10
# while (count != 20):
#     count = count * 1000
#     print(count)

nestedList = [[1,2],[3,4]]
print("嵌套取值：",nestedList[0][1])
for list in nestedList:
    for i in list:
        print(i)
notNestedList = [1,2]
# for list in notNestedList:
#     for i in list:
#         print(i)

scoreDictList = [{"小明":[60,60,60],"小红":[70,70,70]},{"小刚":[61,61,61],"小绿":[71,71,71]}]

print(scoreDictList[0]["小明"][0] >=60)
scoreDictList[0]["小明"].append(60)
print(scoreDictList[0]["小明"])
scoreDictList[0]["小红"].append(60)
print(scoreDictList[0]["小红"])

